package com.ruoyi.distrack.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.distrack.domin.dto.DisTrackQueryDTO;
import com.ruoyi.distrack.domin.entity.DisTrack;
import com.ruoyi.distrack.service.DisTrackService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @author 马兰友
 * @Date: 2024/04/02/19:15
 */
@RestController
@RequestMapping("/distrack")
public class DisTrackController extends BaseController {

    @Resource
    private DisTrackService disTrackService;

    @GetMapping("/{id}")
    public AjaxResult getById (@PathVariable Integer id) {
        return AjaxResult.success(disTrackService.selectDisTrackById(id));
    }

    @GetMapping("/list")
    public TableDataInfo list(DisTrack disTrack) {
        startPage();
        List<DisTrack> list = disTrackService.selectDisTrackList(disTrack);
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody DisTrack disTrack) {
        disTrackService.insertDisTrack(disTrack);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult edit(@RequestBody DisTrack disTrack) {
        disTrackService.updateDisTrack(disTrack);
        return AjaxResult.success();
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove (@PathVariable Integer[] ids) {
        disTrackService.deleteDisTrackByIds(ids);
        return AjaxResult.success();
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, DisTrack disTrack)
    {
        List<DisTrack> list = disTrackService.selectDisTrackList(disTrack);
        ExcelUtil<DisTrack> util = new ExcelUtil<>(DisTrack.class);
        util.exportExcel(response, list, "distrack数据");
    }

    @GetMapping("/pro-list")
    public AjaxResult proList(DisTrack disTrack) {
        return AjaxResult.success(disTrackService.proList(disTrack));
    }


}
